package com.xsmart.oa.dao;


import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
@Component
public interface SystemPermissionListDAO {
/*
* 通过parent_action_id查找action id
* */
    @Select("<script>select action_id from cfgs_action where parent_action_id=#{parent_action_id} </script>")
    List<Map<String,Object>> queryChildNodeList(@Param("parent_action_id") Integer parent_action_id);
/*
* 通过父类id搜索信息
* */
    @Select("<script>SELECT * FROM CFGS_ACTION WHERE <if test=\"PARENT_ACTION_ID==null\">PARENT_ACTION_ID=1</if><if test=\"PARENT_ACTION_ID!=null\">PARENT_ACTION_ID=#{PARENT_ACTION_ID}</if></script>")
    List<Map<String, Object>> querySystemPermissionSubtree(@Param("PARENT_ACTION_ID") Integer PARENT_ACTION_ID);


    /**
     * @param actionId
     * @return
     */
    @Select("<script>SELECT PARENT_ACTION_ID FROM CFGS_ACTION WHERE action_id = #{actionId} </script>")
    Map<String, Object> queryPsystemPermission(@Param("actionId") Integer actionId);

    /*
* 通过搜索条件查询信息
* */
    @Select("<script>select * from CFGS_ACTION where 1=1 <if test=\"PARENT_ACTION_ID==null\">and PARENT_ACTION_ID=1</if><if test=\"PARENT_ACTION_ID!=null\">and PARENT_ACTION_ID=#{PARENT_ACTION_ID}</if><if test=\"action_code!=null and action_code!=''\">and action_code=#{action_code}</if><if test=\"action_desc!=null and action_desc!=''\">and action_desc like concat('%',#{action_desc},'%')</if></script> ")
    List<Map<String,Object>> querySystemPermissionList(Pagination page, Map systemPermissionListMap);

    @Select("<script>select * from CFGS_ACTION where 1=1 <if test=\"action_code!=null and action_code!=''\">and action_code=#{action_code}</if><if test=\"action_desc!=null and action_desc!=''\">and action_desc like concat('%',#{action_desc},'%')</if></script>")
    List<Map<String,Object>> querySystemPermissionListSecond(Pagination page, Map systemPermissionListMap);
/*
* 插入信息
* */
    @Insert("insert into CFGS_ACTION " +
            "(PARENT_ACTION_ID, " +
            "ACTION_CODE," +
            "ACTION_DESC ,"+
            "action_type)"+
            "values (" +
            "#{systemPermissionListMap.PARENT_ACTION_ID}," +
            "#{systemPermissionListMap.ACTION_CODE}, " +
            "#{systemPermissionListMap.ACTION_DESC}," +
            "#{systemPermissionListMap.action_type})")
    int addSystemPermissionList(@Param("systemPermissionListMap")Map systemPermissionListMap);
/*
* 修改信息
* */
    @Update("update CFGS_ACTION " +
            "set " +
            "PARENT_ACTION_ID = #{systemPermissionListMap.PARENT_ACTION_ID}, " +
            "ACTION_CODE = #{systemPermissionListMap.ACTION_CODE}," +
            "ACTION_DESC = #{systemPermissionListMap.ACTION_DESC}," +
            "action_type = #{systemPermissionListMap.action_type} " +
            "where ACTION_ID = #{systemPermissionListMap.ACTION_ID}")
    int modSystemPermissionList(@Param("systemPermissionListMap")Map systemPermissionListMap);
/*
* 删除
* */
    @Delete("DELETE FROM CFGS_ACTION WHERE ACTION_ID=#{action_id}")
    int delSystemPermissionList(Integer action_id);

    @Update("update CFGS_ACTION "+
            "set "+
            "PARENT_ACTION_ID = 1 "+
            "where PARENT_ACTION_ID = #{action_id}")
    int delModSystemPermissionList(Integer action_id);
}
